package com.source.lightfowl.syslog.controller;



import com.source.lightfowl.syslog.pojo.Operation;
import com.source.lightfowl.syslog.service.OperationService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;


/**
 * @Author: 谢春泳
 * @Description: 日志系统的控制器
 *      只提供 1.日志查询
 *            2.日志删除功能
 *      开发笔记:
 *          2.25 controller层的接口写好 测试完毕
 *
 * @Date: 2020/2/25 16:14
 */
@Api(tags = "日志")
@RestController
@RequestMapping
@CrossOrigin
public class OperationController {

    @Autowired
    private OperationService operationService;

    //根据id删除
    @RequestMapping(value = "/operation/{id}",method = RequestMethod.DELETE)
    public void deleteById(@PathVariable String id) {
        operationService.deleteById(id);
    }

    //批量删除
    @RequestMapping(value = "/operationDeleteBatch/ids",method = RequestMethod.DELETE)
    public void deleteByIds(String ids) {
        operationService.deleteByIds(ids);
    }

    //查找
    @RequestMapping(value = "/operation/{id}",method = RequestMethod.GET)
    public Optional<Operation> findById(@PathVariable String id) {
        return operationService.findById(id);
    }


    //查找全部
    @RequestMapping(value = "/operation",method = RequestMethod.GET)
    public List<Operation> findAll() {
        return operationService.findAll();
    }

    //分页查找
    @RequestMapping(value = "/operation/{page},{pageNum}",method = RequestMethod.GET)
    public Page<Operation> findAllPage(@PathVariable int page, @PathVariable int pageNum) {
        return operationService.findAllPage(page,pageNum);
    }

    //
    @RequestMapping(value = "/operationFindByPersonId/id",method = RequestMethod.GET)
    public List<Operation> findByPersonId(String id){
        return operationService.findByPersonId(id);
    }

}

